package com.servlet.project.service;

import com.servlet.project.entity.Activity;
import com.servlet.project.entity.Competition;
import com.servlet.project.util.JdbcUtil;

import java.util.List;

public class CompetitionService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into competition(competitionname,competitiondate,competitionlocation,competitiontype,competitionarranger,competitionjiang) values(?,?,?,?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<Competition> getListAll(int page, int rows, Competition obj) {
        String sql="select * from competition where 1=1 ";
        if(obj.getCompetitionname()!=null&&!obj.getCompetitionname().equals("")){
            sql+=" and competitionname like '%"+obj.getCompetitionname()+"%' ";
        }
        sql+=" limit "+page+","+rows;
        List<Competition> memberList= JdbcUtil.executeQuery(sql,null,Competition.class);
        return memberList;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(Competition obj) {
        String sql="select * from competition where 1=1 ";
        if(obj.getCompetitionname()!=null&&!obj.getCompetitionname().equals("")){
            sql+=" and competitionname like '%"+obj.getCompetitionname()+"%' ";
        }
        List<Competition> memberList= JdbcUtil.executeQuery(sql,null,Competition.class);
        return memberList.size();
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update competition set competitionname=?,competitiondate=?,competitionlocation=?,competitiontype=?,competitionarranger=?,competitionjiang=? where competitionid=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param competitionid
     * @return
     */
    public Competition getId(String competitionid) {
        String sql="select * from competition where competitionid="+competitionid;
        List<Competition> users= JdbcUtil.executeQuery(sql,null,Competition.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from competition  where competitionid=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
